package edu.pku.sei.modeler.uml.commands.umlclass;

import edu.pku.sei.modeler.model.core.MetaModelElement;
import edu.pku.sei.modeler.model.structure.MetaLink;
import edu.pku.sei.modeler.model.structure.MetaNode;
import edu.pku.sei.modeler.model.uml.Kernel.Namespace;
import edu.pku.sei.modeler.model.uml.Kernel.PackageImport;
import edu.pku.sei.modeler.model.uml.Kernel.UMLPackage;
import edu.pku.sei.modeler.uml.commands.ConnectionModelCreateCommand;
import edu.pku.sei.modeler.uml.commands.UMLConnectionCreateCommand;

public class UMLPackageImportCreateCommand extends ConnectionModelCreateCommand {


	public UMLPackageImportCreateCommand(MetaModelElement connectionModel,
			MetaModelElement sourceModel) {
		super(connectionModel, sourceModel);
		// TODO Auto-generated constructor stub
	}

	@Override
	public boolean canExecute() {
		if ( sourceModel instanceof Namespace) {
			return true;
		} else {
			return false;
		}
	}

	@Override
	public void undo() {
		PackageImport packageImport = (PackageImport) connectionModel;
		Namespace sourceNamespace = (Namespace) sourceModel;
		UMLPackage targetPackage = (UMLPackage) targetModel;
		
		packageImport.getImportedPackage().remove(targetPackage);
		sourceNamespace.getPackageImport().remove(packageImport);

	}

	@Override
	public void execute() {
		PackageImport packageImport = (PackageImport) connectionModel;
//		packageImport.setModel(this.source.getModelElement().getModel());
		Namespace sourceNamespace = (Namespace) sourceModel;
		UMLPackage targetPackage = (UMLPackage) targetModel;
		
		packageImport.getImportedPackage().add(targetPackage);
		sourceNamespace.getPackageImport().add(packageImport);

	}

}
